function fmtState(value){
    return value==1?"启用":"禁用";
}

function fmtOpt(value,row,index) {
    var edit = `<a class="btn btn-primary edit" href="javascript:void(0)"><i class="fa fa-edit"></i> 修改</a>`;
    var del= `<a class="btn btn-danger del" href="javascript:void(0)"><i class="fa fa-remove"></i> 删除</a>`;
    return edit+"&emsp;"+del;
}
$(function(){
    $("#grant").dialog({
        title:"用户授权",
        btnName:"授权确认",
        btnBind:function(){
            var rows1=$("#userTb").bootstrapTable("getSelections");
            var rows2=$("#roleTb").bootstrapTable("getSelections");
            var params="uid="+rows1[0].id+"&rid="+rows2[0].id;
            $.post("sys/user/grant",params,function(msg){
                toastr.warning(msg);
                $("#grant").dialog("close");
                $("#userTb").bootstrapTable("refresh");
            },'text');
        }
    });
});
var eventObj={
    "click .edit":function(event,value,row,index){
        $("#update form").setForm(row);
        $("#update").dialog("open");
    },
    "click .del":function(event,value,row){

    }
}

function search(){
    var params={};
    params.name=$("#condition [name=name]").val();
    params.startDate=$("#condition [name=startDate]").val();
    params.endDate=$("#condition [name=endDate]").val();
    $("#userTb").bootstrapTable("refresh",{query:params});
}
function queryParams(params){
    params.name=$("#condition [name=name]").val();
    params.startDate=$("#condition [name=startDate]").val();
    params.endDate=$("#condition [name=endDate]").val();
    return params;
}
function grant(){
    var rows=$("#userTb").bootstrapTable("getSelections");
    if(rows.length!=1){
        swal({
            title:"信息提示",
            text:"请选择一项且只能选择一项待授权！",
            type:"warning",
            confirmButtonText:"确定"
        });
        return;
    }
    var uid=rows[0].id;
    var rid=rows[0].roleId;
    $("#roleTb").bootstrapTable("checkBy",{field:"id",values:[rid]});
    $("#grant").dialog("open");
}
